package com.tarena.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.tarena.domain.Files;
import com.tarena.util.HbnUtil;

public class FilesDao {
	
	/**
	 * @InsertFile
	 * 
	 */
	public void insertFile(Files files){
		Session session  = HbnUtil.getSession();
		try{
			session.beginTransaction();
			session.save(files);
			session.getTransaction().commit();
			session.close();
		}catch(Exception e){
			session.getTransaction().rollback();
			e.printStackTrace();
		}
	}
	
	/**
	 * @GetFiles
	 * @return List<Files>
	 */
	public List<Files> getFiles(){
		Session session  = HbnUtil.getSession();
		Query query = session.createQuery("from Files");
		List<Files> list = query.list();
		return list;
	}	
}
